package com.sleepcamel.resteasyConfigurator.model.command;

import com.sleepcamel.rest.domain.TreeNode;

public class AddTreeNodeCommand extends BaseCommand<TreeNode> {

	@SuppressWarnings("unchecked")
	@Override
	public void execute() {
		try {
		if ( receiver != null && receiver instanceof TreeNode){
			TreeNode entity = (TreeNode) receiver;
			
			if ( arguments == null || arguments.isEmpty() )
				return;
			
			Class<? extends TreeNode> childClass = (Class<? extends TreeNode>) arguments.get(0);
			TreeNode newInstance = childClass.newInstance();
			entity.addChild(newInstance);
		}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}